import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

import exceptions.DivByZeroException;
import exceptions.ParseException;

public class Interpreter {
	public static void main(String[] args) {
		PrintWriter output = new PrintWriter(System.out);
		
		if (args.length < 1) {
			output.println("Illegal argument");
			output.flush();
			return;
		}
		String fileName = args[0];
		Program program = null;
		try {
			program = new Program(new FileReader(new File(fileName)));
		} catch (FileNotFoundException e) {
			output.println("File " + fileName + " not found");
			output.flush();
			return;
		} catch (ParseException e) {
			output.println(e.getMessage());
			output.flush();
			return;
		} catch (IOException e) {
			output.println("IO error");
			output.flush();
			return;
		}
		
		try {
			program.run();
		} catch (DivByZeroException e) {
			output.println(e.getMessage());
			output.flush();
		}
		
	}
}
